package cn.itcast.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author liudo
 * @version 1.0
 * @project mq-demo
 * @description
 * @date 2023/8/19 11:13:21
 */
@Configuration
public class FanoutConfiguration {

    /**
     * 1. 声明队列 fanout.queue
     *
     * @return {@link Queue}
     */
    @Bean
    public Queue fanoutQueue() {
        return new Queue("fanout.queue");
    }

    @Bean
    public Queue fanoutQueue2() {
        return new Queue("fanout.queue2");
    }

    /**
     * 2. 声明交换机
     *
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("fanout.exchange");
    }

    /**
     * 3. 绑定在一起
     *
     * @return
     */
    @Bean
    public Binding bindingQueue1(Queue fanoutQueue) {
        return BindingBuilder.bind(fanoutQueue)
                .to(fanoutExchange());
    }

    @Bean
    public Binding bindingQueue2() {
        return BindingBuilder.bind(fanoutQueue2())
                .to(fanoutExchange());
    }
}
